<?php 

session_start();

require("../../conexao/ConectaMysql.class.php");
require("../../conexao/ControleAcesso.class.php");

require("setor.class.php");
require("gerencia_setor.class.php");

ControleAcesso::verificaSessao();
$conexao = new ConectaMysql();
$gerenciaSetor = new GerenciaSetor($conexao);



if (isset($_POST['Alterar'])){
	$SETid 		= $_POST['SETid'];	
	$SETnome 	= $_POST['SETnome'];
	$SETsigla 	= $_POST['SETsigla'];
	$SETstatus 	= $_POST['SETstatus'];	

	$objectSetor = new Setor($SETid, $SETnome, $SETsigla, $SETstatus);	
	$gerenciaSetor->updateSetor($objectSetor);

}else if(isset($_GET['SETid'])){

	$SETid = $_GET['SETid']; 

	$result_setor = $gerenciaSetor->selectSetor($SETid);
	foreach($result_setor as $row_setor){
		$SETid      = $row_setor["SETid"];
		$SETsigla   = $row_setor["SETsigla"];
		$SETnome	= $row_setor["SETnome"];
		$SETstatus	= $row_setor["SETstatus"];
		
		$objectSetor = new Setor($SETid, $SETnome, $SETsigla, $SETstatus);
		
	}
	?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Setor</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="../../estrutura/css/estruturaCadastro.css" rel="stylesheet" type="text/css" media="screen" />
    <script type="text/javascript" src="../../estrutura/js/jquery.js"></script>
    <script type="text/javascript" src="../../estrutura/js/jquery.validate.js"></script>
    <script type="text/javascript" src="../../estrutura/js/validacaoSetor.js"></script>
    </head>
    
    <body>
    <div align="left">
        <form action="alterar_setor.php" method="post" name="formSetor" id="formSetor" target="_self">
            <input type="hidden" name="SETid" id="SETid" value="<?php echo $objectSetor->getSetorId();?>" />
            <table width="90%"  border="0" align="center">
                <tr>
                    <td colspan="2" bgcolor="#DFEDF7" class="texto"><div align="left"></div><strong>Informe os dados do Setor</strong></td>
                </tr>
                <tr>
                    <td colspan="2" class="texto"><span class="style50">* campos obrigat&oacute;rios</span></td>
                </tr>
                <tr>
                    <td width="21%" bgcolor="#FFFFFF" class="texto">&nbsp;</td>
                    <td width="79%">&nbsp;</td>
                </tr>
                <tr>
                    <td bgcolor="#F1F4F8" class="texto">Nome do Setor: </td>
                    <td>
                        <span class="style50">
                        <label>
                            <input type="text" name="SETnome" id="SETnome" value="<?php echo $objectSetor->getSetorNome();?>" />
                        </label>
                        *</span>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#F1F4F8" class="texto style41"><span class="texto">Sigla do Setor:</span></td>
                    <td>
                        <span class="style50">
                        <label>
                        <input type="text" name="SETsigla" id="SETsigla" value="<?php echo $objectSetor->getSetorSigla();?>" />
                        </label>
                        *</span>        
                    </td>
                </tr>
                <tr>
                  <td bgcolor="#F1F4F8" class="texto style41"><span class="texto">Status do Setor:</span></td>
                  <td>
                      <span class="style50">
                        <select id="SETstatus" name="SETstatus">
                            <option value="1" <?php if ($objectSetor->getSetorStatus() == 1){ echo "SELECTED"; } ?>>Ativo</option>
                            <option value="0" <?php if ($objectSetor->getSetorStatus() == 0){ echo "SELECTED"; } ?>>Inativo</option>                
                        </select>
                      *</span>
                  </td>
                </tr>
                <tr>
                    <td class="texto">&nbsp;</td>
                    <td>&nbsp; </td>
                </tr>
                <tr>
                    <td class="texto style42">&nbsp;</td>
                    <td>
                        <input name="Alterar" type="submit" id="Alterar" value="Confirmar" class="caixa_texto">&nbsp;&nbsp;&nbsp;
                        <input name="voltar" type="button" id="voltar" value="Voltar" class="caixa_texto" OnClick="location.href='formulario.php'"/>          
                    </td>
                </tr>
            </table>
        </form>
    </div>
    </body>
    </html>
<?php } ?>